<?php

namespace app\base\model\goods;

use think\Model;
use think\Db;

class GoodsStatisticsInfo extends Model
{

    // 关闭自动写入时间戳
    protected $autoWriteTimestamp = false;

    protected $table = 'xy_goods.xy_goods_statistics_info';

    public static function GoodsStatistics($goods_id, $field, $num = 1)
    {
        $goods_statistics_info = self::find($goods_id);
        if (empty($goods_statistics_info)) {
            return self::create(['goods_id' => $goods_id, $field => 1, 'create_time' => date('Y-m-d H:i:s')]);
        } else {
            return self::where('goods_id',
                $goods_id)->update([$field => Db::raw("{$field}+{$num}"), 'update_time' => date('Y-m-d H:i:s')]);
        }
    }

}